package com.wechat.scheme.repo.base;

import com.wechat.scheme.entity.base.BaseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

@NoRepositoryBean
public interface SoftDeletableRepo<T extends BaseEntity,String> extends JpaRepository<T ,String> {

    @Modifying
    @Transactional
    @Query("UPDATE #{#entityName} t SET t.deleted = 1 WHERE t.id = ?1")
    void softDeleteById(String id);

    @Modifying
    @Transactional
    @Query("UPDATE #{#entityName} t SET t.deleted = 1 WHERE  t.id in (:ids)")
    void softDeleteByIds(@Param("ids") List<String> ids);

    @Modifying
    @Transactional
    @Query("DELETE FROM #{#entityName} t WHERE  t.id in (:ids)")
    void deleteByIds(@Param("ids") List<String> ids);


}